﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model.WeiXin;
using Xproject.Framework.Utility.Extensions;
using Xproject.Framework.Core.Repositories;
using Xproject.Framework.Utility.ExceptionHandling;
using Xproject.Framework.Core;
using System.Linq.Expressions;

namespace Repository.WeiXinProject
{
    public static class WeiXinConfigRep
    {
        public static WeiXinConfig Get(this IRepositoryAsync<WeiXinConfig> repository, string ID)
        {
            Expression<Func<WeiXinConfig, bool>> express = i => 1 == 1;
            if (!string.IsNullOrEmpty(ID))
            {
                express = express.AndAlso(i => i.ConfigID == ID);
            }
            return repository.Query().Where(express).Select().OrderByDescending(i => i.CreateTime).FirstOrDefault();
        }

        public static List<WeiXinConfig> GetAll(this IRepositoryAsync<WeiXinConfig> repository) {
            Expression<Func<WeiXinConfig, bool>> express = i => 1 == 1;
            
            return repository.Query().Where(express).Select().ToList();
        }
    }
}
